/*
 * @Description: shop controller
 * @Author: zhhuan
 * @LastEditTime: 2024-03-28 15:43:22
 */
const Shop = require("../models/Shop")
const Product = require("../models/Product")

/**
 * @description:获取商店列表
 */
async function getHotList() {
  const list = await Shop.find().sort({ _id: -1 }) // 逆序
  return list
}
/**
 * @description: 商店详情
 * @param {String} id
 */
async function getShopInfo(id) {
  const shop = await Shop.findById(id)
  return shop
}

/**
 * @description: 根据商店id获取商品列表
 * @param {*} shopId 商店id
 * @param {*} tab    tab分类，all等
 */
async function getProductByShopId(id, tab) {
  const list = await Product.find({
    shopId: id,
    tabs: {
      $in: tab
    }
  }).sort({ _id: -1 })
  return list
}
module.exports = { getHotList, getShopInfo, getProductByShopId }
